package com.hu.hutool.xxl_job;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * xxl-job的执行器
 *
 * @Author CazCen
 * @Date 2021/11/20 23:28
 */
@Component
public class XxlJobHandle {
    private static Logger logger = LoggerFactory.getLogger(XxlJobHandle.class);

    @XxlJob(value = "myFirstXxlJobHandler")
    public void myFirstXxlJobHandler() throws Exception {

        // 获取xxl-job 参数
        String jobParam = XxlJobHelper.getJobParam();

        String jobLogFileName = XxlJobHelper.getJobLogFileName();

        XxlJobHelper.log("jobLogFileName:{}", jobLogFileName);

        String[] split = jobParam.split(",");
        
        XxlJobHelper.log("my first xxl-job operation 每分钟执行一次  接收的参数：", jobParam);

        logger.info("logger.info------my first xxl-job operation  每分钟执行一次  接收的参数:{} !!! ", jobParam);
    }


    @XxlJob(value = "mySecondXxlJobHandler")
    public void mySecondXxlJobHandler() throws Exception {

        XxlJobHelper.getJobId();

        // 获取xxl-job 参数
        String jobParam = XxlJobHelper.getJobParam();

        String jobLogFileName = XxlJobHelper.getJobLogFileName();

        XxlJobHelper.log("jobLogFileName:{}", jobLogFileName);

        String[] split = jobParam.split(",");

        // 模拟异常，发送邮件信息
        int i = 1 / 0;

        XxlJobHelper.log("my Second xxl-job operation 每分钟执行一次  接收的参数：", jobParam);

        logger.info("logger.info------my Second xxl-job operation  每分钟执行一次  接收的参数:{} !!! ", jobParam);
    }

}
